package com.du.quant.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.du.quant.entity.StockHistory;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDate;
import java.util.List;

@Mapper
public interface StockHistoryMapper extends BaseMapper<StockHistory> {

    @Select("SELECT * FROM stock_history WHERE stock_code = #{stockCode} AND trade_date >= #{startDate} ORDER BY trade_date DESC")
    List<StockHistory> selectByStockCodeAndDate(@Param("stockCode") String stockCode,
                                                @Param("startDate") LocalDate startDate);

    @Select("SELECT trade_date FROM stock_history WHERE stock_code = #{stockCode} ORDER BY trade_date DESC LIMIT 1")
    LocalDate selectLatestTradeDate(@Param("stockCode") String stockCode);

    @Delete("DELETE FROM stock_history WHERE stock_code = #{stockCode}")
    void deleteByStockCode(@Param("stockCode") String stockCode);
}